package com.lonely.web.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lonely.common.core.domain.Select;
import com.lonely.common.core.domain.api.R;
import com.lonely.system.domain.dto.customer.SysCustomerPageQueryDto;
import com.lonely.system.domain.dto.customer.SysCustomerSubmitDto;
import com.lonely.system.domain.vo.system.customer.SysCustomerPageQueryVo;
import com.lonely.system.service.ISysCustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 黄志标
 * @date: 2025/6/17 17:07
 * @description: 客户列表请求处理器
 */
@RestController
@RequestMapping("/systemManage/customer")
@Api(tags = "系统管理/客户管理")
public class SysCustomerController {

    @Autowired
    private ISysCustomerService sysCustomerService;

    /**
     * 分页查询
     *
     * @param queryDto
     * @return
     */
    @PostMapping("/page")
    @ApiOperation(value = "分页查询")
//    @SaCheckPermission("system:customer:page")
    public R<Page<SysCustomerPageQueryVo>> page(@RequestBody SysCustomerPageQueryDto queryDto) {
        return R.data(this.sysCustomerService.page(queryDto));
    }


    /**
     * 创建客户
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/create")
    @ApiOperation(value = "创建客户")
    @SaCheckPermission("system:customer:create")
    public R<Boolean> create(@RequestBody @Validated SysCustomerSubmitDto submitDto) {
        this.sysCustomerService.create(submitDto);
        return R.status(true);
    }


    /**
     * 编辑客户
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/edit")
    @ApiOperation(value = "编辑客户")
    @SaCheckPermission("system:customer:edit")
    public R<Boolean> edit(@RequestBody @Validated SysCustomerSubmitDto submitDto) {
        this.sysCustomerService.edit(submitDto);
        return R.status(true);
    }

    /**
     * 启用客户
     *
     * @param id
     * @return
     */
    @GetMapping("/enabled/{id}")
    @ApiOperation(value = "启用客户")
    @SaCheckPermission("system:customer:enabled")
    public R<Boolean> enabled(@PathVariable("id") Long id) {
        this.sysCustomerService.enabled(id);
        return R.status(true);
    }

    /**
     * 禁用客户
     *
     * @param id
     * @return
     */
    @GetMapping("/disable/{id}")
    @ApiOperation(value = "禁用客户")
    @SaCheckPermission("system:customer:disable")
    public R<Boolean> disable(@PathVariable("id") Long id) {
        this.sysCustomerService.disable(id);
        return R.status(true);
    }

    /**
     * 获取客户下拉列表
     *
     * @return
     */
    @GetMapping("/getCustomerSelect")
    @ApiOperation(value = "获取客户下拉列表")
    public R<List<Select>> getCustomerSelect() {
        return R.data(this.sysCustomerService.getCustomerSelect());
    }
}
